Hi all, i found this link https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014567735 And i want to compare the access rights with given groups My idea was write the name of the groups (strings) into a skiplist, than create an alphabetically list of all groups, and then iterate the whole thing,
but something is wrong with my idea, he iterate to often and i don't know why! Here is my code...
Group g
string gname
Skip skp = createString()
Skip skipUserList = create
string s
//Default Project User
string dPu1 = "DBManager"
string dPu2 = "Test"
string dPu3 = "Admins"
string dPu4 = "readonly"
string dPu5 = "user"
string dPu6 = "readwrite"
string dPu7 = "Everyone else"
string stringUserList[] = {dPu1, dPu2, dPu3, dPu4, dPu5, dPu6, dPu7}
int i
for (i=0; i<sizeof(stringUserList); i++)
{
put(skipUserList, stringUserList[i], stringUserList[i])
}
void recurseFolders( Item parentItem )
{
string itemType = type( parentItem )
if ( ( itemType == "Folder" ) || ( itemType == "Project" ) )
{
Item childItem
for childItem in folder( parentItem ) do
{
recurseFolders( childItem )
}
}
if(itemType == "Formal" || itemType == "Link" || itemType == "Project")
{
print itemType ":\n"
print fullName( parentItem ) "\n"
AccessRec ar
for ar in all parentItem do
{
for g in groupList do
{
gname = g.name;
put(skp, gname"", gname"")
}
for gname in skp do
{
for s in skipUserList do
{
//print "G: "gname "\n"
if(s == gname)
{
if ( isDefault( ar ) )
{
print "\tDefault"
}
else
{
print "\t" username( ar )
}
string r = ((read ar) ? "R" : "")
string m = ((modify ar) ? "M" : "")
string c = ((create ar) ? "C" : "")
string d = ((delete ar) ? "D" : "")
string a = ((control ar) ? "A" : "")
string accessStr = r m c d a ""
if ( null accessStr )
{
accessStr = "None"
}
print "-"accessStr "\n"
}
}
}
}
}
}
recurseFolders(item(fullName current Folder))
meinhana - Tue Sep 08 04:49:32 EDT 2015 | ||||||||||||
Re: How to compare groups from access rights?
The algo seems to be to log access rights for each member of stringUserList for each element of parentItem ...
Group g
string gname
Skip skp = createString()
Skip skipUserList = createString()
string s
//Default Project User
string stringUserList[] = {"DBManager", "Test", "Admins", "readonly", "user", "readwrite", "Everyone else"}
string r, m, c, d, a, accessStr
int i
for (i=0; i<sizeof(stringUserList); i++){
put(skipUserList, stringUserList[i], stringUserList[i])
}
void recurseFolders( Item parentItem ) {
string itemType = type( parentItem )
// do you really need a test here ? ;)
// if(itemType == "Formal" || itemType == "Link" || itemType == "Project")
{
print itemType ":\n"
print fullName( parentItem ) "\n"
AccessRec ar
for ar in all parentItem do {
for g in groupList do {
gname = g.name;
put(skp, gname"", gname"")
}
for s in skipUserList do {
if ( find(skp, s, gname) ){
if ( isDefault( ar ) ) print "\tDefault"
else print "\t" username( ar )
r = ((read ar) ? "R" : "")
m = ((modify ar) ? "M" : "")
c = ((create ar) ? "C" : "")
d = ((delete ar) ? "D" : "")
a = ((control ar) ? "A" : "")
accessStr = r m c d a ""
if ( null accessStr ) accessStr = "None"
print "-"accessStr "\n"
}
}
}
}
if ( ( itemType == "Folder" ) || ( itemType == "Project" ) ) {
Item childItem
for childItem in folder( parentItem ) do recurseFolders( childItem )
}
}
recurseFolders(item(fullName current Folder))
delete skipUserList
delete skp
| ||||||||||||
Re: How to compare groups from access rights? pommCannelle - Tue Sep 08 08:27:37 EDT 2015
The algo seems to be to log access rights for each member of stringUserList for each element of parentItem ...
Group g
string gname
Skip skp = createString()
Skip skipUserList = createString()
string s
//Default Project User
string stringUserList[] = {"DBManager", "Test", "Admins", "readonly", "user", "readwrite", "Everyone else"}
string r, m, c, d, a, accessStr
int i
for (i=0; i<sizeof(stringUserList); i++){
put(skipUserList, stringUserList[i], stringUserList[i])
}
void recurseFolders( Item parentItem ) {
string itemType = type( parentItem )
// do you really need a test here ? ;)
// if(itemType == "Formal" || itemType == "Link" || itemType == "Project")
{
print itemType ":\n"
print fullName( parentItem ) "\n"
AccessRec ar
for ar in all parentItem do {
for g in groupList do {
gname = g.name;
put(skp, gname"", gname"")
}
for s in skipUserList do {
if ( find(skp, s, gname) ){
if ( isDefault( ar ) ) print "\tDefault"
else print "\t" username( ar )
r = ((read ar) ? "R" : "")
m = ((modify ar) ? "M" : "")
c = ((create ar) ? "C" : "")
d = ((delete ar) ? "D" : "")
a = ((control ar) ? "A" : "")
accessStr = r m c d a ""
if ( null accessStr ) accessStr = "None"
print "-"accessStr "\n"
}
}
}
}
if ( ( itemType == "Folder" ) || ( itemType == "Project" ) ) {
Item childItem
for childItem in folder( parentItem ) do recurseFolders( childItem )
}
}
recurseFolders(item(fullName current Folder))
delete skipUserList
delete skp
HI, tanks for your answer :) Have you tried this code? I mean with "extra iteration" that -> Output :
Project: | ||||||||||||
Re: How to compare groups from access rights? meinhana - Tue Sep 08 08:41:54 EDT 2015 HI, tanks for your answer :) Have you tried this code? I mean with "extra iteration" that -> Output :
Project:
Strange ... Here after the output i obtain ...
Folder:
/1.3.06.4 Logiciel SECU/Définition
Default-R
Système-RMCD
Validation_Logiciels-RMCD
Admins-RMCDA
Système_Adm-RMCDA
Formal:
/1.3.06.4 Logiciel SECU/Définition/SRS_SECU
Default-R
Système-RMCD
Validation_Logiciels-RMCD
Admins-RMCDA
Système_Adm-RMCDA
Formal:
/1.3.06.4 Logiciel SECU/Définition/SDD_SECU
Default-R
Système-RMCD
Validation_Logiciels-RMCD
Admins-RMCDA
Système_Adm-RMCDA
Formal:
/1.3.06.4 Logiciel SECU/Définition/SDD_SECU_Functions_old
Default-R
Système-RMCD
Validation_Logiciels-RMCD
Admins-RMCDA
Système_Adm-RMCDA
| ||||||||||||
Re: How to compare groups from access rights? pommCannelle - Tue Sep 08 08:45:13 EDT 2015
Strange ... Here after the output i obtain ...
Folder:
/1.3.06.4 Logiciel SECU/Définition
Default-R
Système-RMCD
Validation_Logiciels-RMCD
Admins-RMCDA
Système_Adm-RMCDA
Formal:
/1.3.06.4 Logiciel SECU/Définition/SRS_SECU
Default-R
Système-RMCD
Validation_Logiciels-RMCD
Admins-RMCDA
Système_Adm-RMCDA
Formal:
/1.3.06.4 Logiciel SECU/Définition/SDD_SECU
Default-R
Système-RMCD
Validation_Logiciels-RMCD
Admins-RMCDA
Système_Adm-RMCDA
Formal:
/1.3.06.4 Logiciel SECU/Définition/SDD_SECU_Functions_old
Default-R
Système-RMCD
Validation_Logiciels-RMCD
Admins-RMCDA
Système_Adm-RMCDA
I should try that code on a other computer :D I will report | ||||||||||||
Re: How to compare groups from access rights? With more prints ->
S: Admins - Gname: Admins .... he iterate 6 times (to "readwrite") All in all i have 42 outputs per project/formal/link ???? | ||||||||||||
Re: How to compare groups from access rights? meinhana - Wed Sep 09 03:16:11 EDT 2015 With more prints ->
S: Admins - Gname: Admins .... he iterate 6 times (to "readwrite") All in all i have 42 outputs per project/formal/link ???? ( post your code ? :) ) | ||||||||||||
Re: How to compare groups from access rights? pommCannelle - Wed Sep 09 06:26:57 EDT 2015 ( post your code ? :) ) The same as before... :/ I cant find the failure | ||||||||||||
Re: How to compare groups from access rights? meinhana - Wed Sep 09 06:39:41 EDT 2015 The same as before... :/ I cant find the failure I think the problem is, you aren't really comparing the username of the ar, with the list of groups you have. Rather, comparing list of groups from skipUserList and list of groups itself. That's the reason why you're seeing DBManager-R remain constant (since that's the value of the ar), while the s and gname varies.. I'd say, it is better to put the "for g in groupList" loop out of the recursive function and have that pre-populated (I'm not sure why you even need it, if you're confident that the array you supply are valid group names). Within the "for ar in all parentItem do" loop, get the username(ar), and compare that against skipUserList and print the values (or compare against both skips, depending on your exact need).
Hope that helps.
**Edited - the part I mentioned about isDefault is wrong. I stand to be corrected. | ||||||||||||
Re: How to compare groups from access rights? SudarshanRao - Wed Sep 09 07:46:55 EDT 2015 I think the problem is, you aren't really comparing the username of the ar, with the list of groups you have. Rather, comparing list of groups from skipUserList and list of groups itself. That's the reason why you're seeing DBManager-R remain constant (since that's the value of the ar), while the s and gname varies.. I'd say, it is better to put the "for g in groupList" loop out of the recursive function and have that pre-populated (I'm not sure why you even need it, if you're confident that the array you supply are valid group names). Within the "for ar in all parentItem do" loop, get the username(ar), and compare that against skipUserList and print the values (or compare against both skips, depending on your exact need).
Hope that helps.
**Edited - the part I mentioned about isDefault is wrong. I stand to be corrected. Thanks, i took the "for group" loop out, but sill the same problem... I want to explain you, why i want to do that... I have a list(on paper) of groups and their access right( for formals, links and projects) and I want to check if the groups(on the paper) are the same as defined in DOORS At last i want to write them into a CSV file, like "Name of module or etc: xxx " Group: 1 | 2 | 3 | ... Defaults: R | RMCDA | RMC |..... Check: true | true | false |.... (compare the give access rights(on paper) with the defined/ set access right Maybe i think too complicated... | ||||||||||||
Re: How to compare groups from access rights? meinhana - Wed Sep 09 08:01:31 EDT 2015 Thanks, i took the "for group" loop out, but sill the same problem... I want to explain you, why i want to do that... I have a list(on paper) of groups and their access right( for formals, links and projects) and I want to check if the groups(on the paper) are the same as defined in DOORS At last i want to write them into a CSV file, like "Name of module or etc: xxx " Group: 1 | 2 | 3 | ... Defaults: R | RMCDA | RMC |..... Check: true | true | false |.... (compare the give access rights(on paper) with the defined/ set access right Maybe i think too complicated... Ok. If your objective of using "for group" loop is only to verify if a given group on paper is a valid group or not, you can as well use "existsGroup" and/or "existsUser" perms (either while creating skipUserList, or while checking access records, depending on how you want the output). For now, to keep this discussion simple, I've removed "for group" part entirely in the following sample, which I hope works at your end :-)
Group g
string gname
Skip skipUserList = createString()
string s, recordName
//Default Project User
string dPu1 = "DBManager"
string dPu2 = "Test"
string dPu3 = "Admins"
string dPu4 = "readonly"
string dPu5 = "user"
string dPu6 = "readwrite"
string dPu7 = "Everyone else"
string stringUserList[] = {dPu1, dPu2, dPu3, dPu4, dPu5, dPu6, dPu7}
int i
for (i=0; i<sizeof(stringUserList); i++)
{
put(skipUserList, stringUserList[i], stringUserList[i])
}
void recurseFolders( Item parentItem )
{
string itemType = type( parentItem )
print itemType ":\n"
print fullName( parentItem ) "\n"
AccessRec ar
for ar in all parentItem do
{
recordName = username(ar)
if(isDefault(ar))
{
recordName = "Everyone else"
}
//Print details only if record matches with the list provided in line 16
if(find(skipUserList, recordName))
{
if ( isDefault( ar ) )
{
print "\tDefault"
}
else
{
print "\t" username( ar )
}
string r = ((read ar) ? "R" : "")
string m = ((modify ar) ? "M" : "")
string c = ((create ar) ? "C" : "")
string d = ((delete ar) ? "D" : "")
string a = ((control ar) ? "A" : "")
string accessStr = r m c d a ""
if ( null accessStr )
{
accessStr = "None"
}
print "-"accessStr "\n"
}
}
if ( ( itemType == "Folder" ) || ( itemType == "Project" ) )
{
Item childItem
for childItem in folder( parentItem ) do
{
recurseFolders( childItem )
}
}
}
recurseFolders(item(fullName current Folder))
delete skipUserList
Hope that helps! | ||||||||||||
Re: How to compare groups from access rights? SudarshanRao - Wed Sep 09 10:16:42 EDT 2015 Ok. If your objective of using "for group" loop is only to verify if a given group on paper is a valid group or not, you can as well use "existsGroup" and/or "existsUser" perms (either while creating skipUserList, or while checking access records, depending on how you want the output). For now, to keep this discussion simple, I've removed "for group" part entirely in the following sample, which I hope works at your end :-)
Group g
string gname
Skip skipUserList = createString()
string s, recordName
//Default Project User
string dPu1 = "DBManager"
string dPu2 = "Test"
string dPu3 = "Admins"
string dPu4 = "readonly"
string dPu5 = "user"
string dPu6 = "readwrite"
string dPu7 = "Everyone else"
string stringUserList[] = {dPu1, dPu2, dPu3, dPu4, dPu5, dPu6, dPu7}
int i
for (i=0; i<sizeof(stringUserList); i++)
{
put(skipUserList, stringUserList[i], stringUserList[i])
}
void recurseFolders( Item parentItem )
{
string itemType = type( parentItem )
print itemType ":\n"
print fullName( parentItem ) "\n"
AccessRec ar
for ar in all parentItem do
{
recordName = username(ar)
if(isDefault(ar))
{
recordName = "Everyone else"
}
//Print details only if record matches with the list provided in line 16
if(find(skipUserList, recordName))
{
if ( isDefault( ar ) )
{
print "\tDefault"
}
else
{
print "\t" username( ar )
}
string r = ((read ar) ? "R" : "")
string m = ((modify ar) ? "M" : "")
string c = ((create ar) ? "C" : "")
string d = ((delete ar) ? "D" : "")
string a = ((control ar) ? "A" : "")
string accessStr = r m c d a ""
if ( null accessStr )
{
accessStr = "None"
}
print "-"accessStr "\n"
}
}
if ( ( itemType == "Folder" ) || ( itemType == "Project" ) )
{
Item childItem
for childItem in folder( parentItem ) do
{
recurseFolders( childItem )
}
}
}
recurseFolders(item(fullName current Folder))
delete skipUserList
Hope that helps! Thank you! If i need more help, i will write here :) | ||||||||||||
Re: How to compare groups from access rights? Am i stupid or something? This script annoying me.... I want only write the names into a csv file ?!
void recurseFolders( Item parentItem )
{
if(!canOpenFile(fileString, true))
{
infoBox dataCannotOpen fileString "\n"
print dataCannotOpen fileString "\n"
halt
}
else
{
fileStream = write fileString
}
string itemType = type( parentItem )
print itemType ":\n"
fileStream << itemType ";"
print fullName( parentItem ) "\n"
fileStream << fullName (parentItem) "\n"
Output
| ||||||||||||
Re: How to compare groups from access rights? Can anyone help me? | ||||||||||||
Re: How to compare groups from access rights? meinhana - Mon Sep 14 03:24:55 EDT 2015 Can anyone help me? You have
You are strange like a women. You are a women, aren't you? | ||||||||||||
Re: How to compare groups from access rights? Wolfgang Uhr - Mon Sep 14 04:22:00 EDT 2015 You have
You are strange like a women. You are a women, aren't you? Yes, i am But my last Question refers to the "full codes" from the top, i find it unnecessary to open a new topic for that... And this "Am i stupid or something" - I was very annoyed, because i can't see the problem there | ||||||||||||
Re: How to compare groups from access rights? meinhana - Mon Sep 14 04:30:11 EDT 2015 Yes, i am But my last Question refers to the "full codes" from the top, i find it unnecessary to open a new topic for that... And this "Am i stupid or something" - I was very annoyed, because i can't see the problem there Incomplete codes allways tends to do incomplete things
string fileString = "C:\\Temp\\Test.txt"; string dataCannotOpen = "Some useful words"; Stream fileStream = write(fileString); void recurseFolders( Item parentItem ) { if(!canOpenFile(fileString, true)) { infoBox dataCannotOpen fileString "\n" print dataCannotOpen fileString "\n" halt } else { fileStream = write fileString } string itemType = type( parentItem ) print itemType ":\n" fileStream << itemType";" print fullName( parentItem ) "\n" fileStream << fullName (parentItem) "\n" }
Module mdlWork = current; Item itmWork = item(fullName(mdlWork)); recurseFolders(itmWork);
Best regards Wolfgang | ||||||||||||
Re: How to compare groups from access rights? Wolfgang Uhr - Mon Sep 14 06:55:02 EDT 2015 Incomplete codes allways tends to do incomplete things
string fileString = "C:\\Temp\\Test.txt"; string dataCannotOpen = "Some useful words"; Stream fileStream = write(fileString); void recurseFolders( Item parentItem ) { if(!canOpenFile(fileString, true)) { infoBox dataCannotOpen fileString "\n" print dataCannotOpen fileString "\n" halt } else { fileStream = write fileString } string itemType = type( parentItem ) print itemType ":\n" fileStream << itemType";" print fullName( parentItem ) "\n" fileStream << fullName (parentItem) "\n" }
Module mdlWork = current; Item itmWork = item(fullName(mdlWork)); recurseFolders(itmWork);
Best regards Wolfgang
Stream fileStream
string fileString = "C:\\Test.csv"
string dataCannotOpen = "Cannot open! "
//...
void recurseFolders( Item parentItem )
{
if(!canOpenFile(fileString, true))
{
infoBox dataCannotOpen fileString "\n"
print dataCannotOpen fileString "\n"
halt
}
else
{
fileStream = write fileString
}
string itemType = type( parentItem )
if(itemType == "Formal" || itemType == "Link" || itemType == "Project")
{
print itemType ":\n"
fileStream << itemType ";"
print fullName( parentItem ) "\n"
fileStream << fullName (parentItem) "\n"
AccessRec ar
for ar in all parentItem do
{
//fileStream << itemType ";" fullName(parentItem) "\n"
recordName = username(ar)
if(isDefault(ar))
{
recordName = "Everyone else"
}
//Print details only if record matches with the list provided in line 35
if(find(skipUserList, recordName))
{
if ( isDefault( ar ) )
{
//print "\tDefault"
}
else
{
//print "\t" username( ar )
}
string r = ((read ar) ? "R" : "")
string m = ((modify ar) ? "M" : "")
string c = ((create ar) ? "C" : "")
string d = ((delete ar) ? "D" : "")
string a = ((control ar) ? "A" : "")
string accessStr = r m c d a ""
if ( null accessStr )
{
accessStr = "None"
}
//print "-"accessStr "\n"
}
}
}
if ( ( itemType == "Folder" ) || ( itemType == "Project" ) )
{
Item childItem
for childItem in folder( parentItem ) do
{
recurseFolders( childItem )
}
}
}
//___________________________________________________________________________________
recurseFolders(item(fullName current Folder))
delete skipUserList
flush(fileStream)
close(fileStream)
The same as yours... Output print ->
Project:
Output file -> Formal /Test_Project/newModule
| ||||||||||||
Re: How to compare groups from access rights? The output file is being overwritten in each recursive call since you are assigning fileStream as write inside the recursive function. So get that if and else statement out of the recurseFolders function, should work as expected. | ||||||||||||
Re: How to compare groups from access rights? SudarshanRao - Tue Sep 15 10:49:22 EDT 2015 The output file is being overwritten in each recursive call since you are assigning fileStream as write inside the recursive function. So get that if and else statement out of the recurseFolders function, should work as expected. Thank you ! This was the problem... Now it works :) | ||||||||||||